#include "system.h"
volatile uint32_t SysTickdelayCnt = 0;

/*设置TIM3输入捕获中断(No 16)为最高优先级(0b00);
  设置DMA中断(No 9)为次高优先级(0b01)*/
void NVIC_Init(void)
{
	NVIC->IP[4] = 0x80000000;/*TIM3 IT优先级最高,TIMER14 IT优先级最低(用于Modbus帧间隔)*/
	NVIC->IP[3] = 0x00000000;/*TIM1 BRK优先级最高*/	
	NVIC->IP[2] = 0x00004000;/*DMA IT优先级第2*/
	SCB->SHP[1] = 0x80000000;/*SysTick优先级最低*/
    //NVIC->ISER[0] |= (1<<16) + (1<<9);/*使能TIM3和DMA中断调用*/
		//NVIC->ISER[0] |= (1<<16);
}

/*产生1ms周期时基中断*/
void Systick_Init(void)
{
	SysTick->LOAD = 64000 - 1;/*64M/64K = 1K*/
	SysTick->VAL = 0;
	SysTick->CTRL = (1<<2)+(1<<1);/*CLKSOURCE(bit2) = 1 时钟源为内部时钟 TICKINT(bit1) = 1 使能滴答定时器中断*/
	//SysTick->CTRL |= (1<<0);/*使能滴答定时器*/
}

void DelayMs(uint32_t ms)
{
	SysTickdelayCnt = ms;
	while(SysTickdelayCnt);
}

void Systick_Enable(void)
{
	SysTick->CTRL |= (1<<0);/*使能滴答定时器*/	
}

void SysTick_Disable(void)
{
	SysTick->CTRL &=~ (1<<0);/*使能滴答定时器*/
}
